

#include "CxCapture.h"



using namespace ImitateTansfer;

ImpCxCapture::ImpCxCapture(LPCSTR filename):m_capture(NULL)
{
    m_isOpened=OpenFile(filename);
}

ImpCxCapture::~ImpCxCapture()
{
	if(m_capture!=NULL)
		cvReleaseCapture(&m_capture);
}


IplImage * ImpCxCapture::GetFrame()
{
	if(m_capture==NULL)return NULL;
	IplImage *img;

	if((img=cvQueryFrame(m_capture))!=NULL)
    {
        m_currentframe=cvGetCaptureProperty(m_capture,CV_CAP_PROP_POS_FRAMES);
		return cvCloneImage(img);
    }
	else return NULL;
}

bool	ImpCxCapture::OpenFile(LPCSTR filename)
{
	if(m_capture!=NULL)cvReleaseCapture(&m_capture);
	m_capture=cvCreateFileCapture(filename);
    if(m_capture==NULL)return false;
    m_totalframe=cvGetCaptureProperty(m_capture,CV_CAP_PROP_FRAME_COUNT );
	return true;
}


inline	double	ImpCxCapture::GetFrameRate()const
{
    return ((double)m_currentframe)/((double)m_totalframe);//cvGetCaptureProperty(m_capture,CV_CAP_PROP_POS_AVI_RATIO);
}


inline void     ImpCxCapture::SetFrameRate(double value)
{
    int current=m_totalframe*value;
    cvSetCaptureProperty(m_capture,CV_CAP_PROP_POS_FRAMES,(double)current);
}
